import { SortUtils } from "../../api/math/SortUtils";
import { HashMap } from "../../api/struct/HashMap";
import { CDLotteryBase } from "../excel/CDLotteryBase";


/**
 * 扩展-抽奖
 */
export abstract class CELotteryBase {

    /**类型映射表 */
    public static typeMap = new HashMap<number, CDLotteryBase[]>();

    /**初始化 */
    public static init(): void {
        {
            const vs = CDLotteryBase.datas.getValues();
            for (let i = 0, len = vs.length; i < len; i++) {
                const config = vs[i];
                let list = this.typeMap.get(config.lotteryType);
                if (!list) {
                    list = [];
                    this.typeMap.put(config.lotteryType, list);
                }
                list.push(config);
            }
        }

        //根据优先级排序
        {
            const vs = this.typeMap.getValues();
            for (let i = 0, len = vs.length; i < len; i++) {
                SortUtils.quickSort(vs[i], this.cmpLottery);
            }
        }
    }


    /**
     * 比较排序
     * @param c1 
     * @param c2 
     */
    private static cmpLottery(c1: CDLotteryBase, c2: CDLotteryBase): number {
        if (c1.order !== c2.order) {
            return c1.order - c2.order;
        }
        return c1.id - c2.id;
    }
}